import facade
from xjlibrary.MRabbitMQ.useMQ.recvmq import RecvMQUse

# 数据库链接
from xjlibrary.configread import MyConfigParser
from xjlibrary.our_file_dir.base_dir import BaseDir

curPath = BaseDir.get_file_dir_absolute(__file__)
logger = facade.get_streamlogger()
mysqlutils = facade.MysqlUtiles(BaseDir.get_new_path(BaseDir.get_upper_dir(curPath, -1),"db.ini"), "db", logger=logger)


class Recv(RecvMQUse):
    def __init__(self, cofig, queuetest):
        super(Recv, self).__init__(cofig, queuetest)

    def callback(self, ch, method, properties, body):
        global ConnDB
        sql = body.decode('utf-8')
        print('recv body: %s' % sql)
        mysqlutils.ExeSqlToDB(sql)
        super().callback(ch, method, properties, body)


if __name__ == "__main__":
    config = BaseDir.get_new_path(BaseDir.get_upper_dir(curPath, -1), "db.ini")
    GolobalConfig = MyConfigParser().get_conf_dict_file(config)
    queueCenter2Node = GolobalConfig['get_article']['MQQueueNode2Center']
    recv = Recv(config, queueCenter2Node)
    recv.run()
